let { projectRootPath } = require("../../../util/index");
let { getNewApp } = require(`${projectRootPath}/app/index.js`);
let {
  createTask,
  getTaskByPagination,
  editTaskByUuid,
  removeTaskByUuid,
  getRoleByPagination,
  removeRoleByUuid,
  editRoleByUuid,
  getRoleByAll,
} = require(`${projectRootPath}/service/task/index.js`);
let app = getNewApp();

// 创建任务
app.post("/create", async (req, res) => {
  try {
    let result = await createTask(req.body);
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});

// 获取任务分页数据
app.post("/get/pagination", async (req, res) => {
  try {
    let result = await getTaskByPagination(req.body);
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});
// 通过 uuid 编辑任务
app.post("/edit/uuid", async (req, res) => {
  try {
    let result = await editTaskByUuid(req.body);
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});
// 通过 uuid 删除任务
app.post("/remove/uuid", async (req, res) => {
  try {
    let result = await removeTaskByUuid(req.body);
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});
module.exports = app;
